package cn.iocoder.yudao.module.biz.controller.admin.htPlanDetail;

import cn.iocoder.yudao.module.biz.controller.admin.htHiddentroubleflow.vo.HiddentroubleflowPageJoinVO;
import cn.iocoder.yudao.module.biz.controller.admin.htPlan.vo.HtPlanPageReqVO;
import cn.iocoder.yudao.module.biz.controller.admin.htPlan.vo.HtPlanRiskVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.biz.controller.admin.htPlanDetail.vo.*;
import cn.iocoder.yudao.module.biz.dal.dataobject.htPlanDetail.HtPlanDetailDO;
import cn.iocoder.yudao.module.biz.convert.htPlanDetail.HtPlanDetailConvert;
import cn.iocoder.yudao.module.biz.service.htPlanDetail.HtPlanDetailService;

@Api(tags = "管理后台 - 隐患排查计划详情")
@RestController
@RequestMapping("/biz/ht-plan-detail")
@Validated
public class HtPlanDetailController {

    @Resource
    private HtPlanDetailService htPlanDetailService;

    @PostMapping("/create")
    @ApiOperation("创建隐患排查计划详情")
//    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detail:create')")
    public CommonResult<String> createHtPlanDetail(@Valid @RequestBody HtPlanDetailCreateReqVO createReqVO) {
        return success(htPlanDetailService.createHtPlanDetail(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新隐患排查计划详情")
//    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detail:update')")
    public CommonResult<Boolean> updateHtPlanDetail(@Valid @RequestBody HtPlanDetailUpdateReqVO updateReqVO) {
        htPlanDetailService.updateHtPlanDetail(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除隐患排查计划详情")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
//    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detail:delete')")
    public CommonResult<Boolean> deleteHtPlanDetail(@RequestParam("id") String id) {
        htPlanDetailService.deleteHtPlanDetail(id);
        return success(true);
    }

    @GetMapping("/getRiskInfoPage")
    @ApiOperation("获得隐患排查计划详情")
    @ApiImplicitParam(name = "id", value = "计划编号", required = true, example = "1024", dataTypeClass = String.class)
//    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detail:query')")
    public CommonResult<PageResult<HtPlanRiskVO>> getHtPlanDetail(@Valid HtPlanDetailPageReqVO pageVO) {
        PageResult<HtPlanRiskVO> result=new PageResult<>();
        int pageNo=pageVO.getPageNo();
        pageVO.setPageNo((pageNo-1)*pageVO.getPageSize());

        List<HtPlanRiskVO>  list = htPlanDetailService.queryPlanDetailBy(pageVO);
        Integer count= htPlanDetailService.queryPlanDetailByCount(pageVO);
        result.setList(list);
        result.setTotal((long) count);

        return success(result);
    }

    @GetMapping("/list")
    @ApiOperation("获得隐患排查计划详情列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
//    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detail:query')")
    public CommonResult<List<HtPlanDetailRespVO>> getHtPlanDetailList(@RequestParam("ids") Collection<String> ids) {
        List<HtPlanDetailDO> list = htPlanDetailService.getHtPlanDetailList(ids);
        return success(HtPlanDetailConvert.INSTANCE.convertList(list));
    }

//    @GetMapping("/page")
//    @ApiOperation("获得隐患排查计划详情分页")
//    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detail:query')")
//    public CommonResult<PageResult<HtPlanDetailJoinPageVO>> getHtPlanDetailPage(@Valid HtPlanPageReqVO pageVO) {
//        PageResult<HtPlanDetailJoinPageVO> result=new PageResult<>();
//        int pageNo=pageVO.getPageNo();
//        pageVO.setPageNo((pageNo-1)*pageVO.getPageSize());
//
//        List<HtPlanDetailJoinPageVO> list = htPlanDetailService.selectHtPlanPage(pageVO);
//        Integer count= htPlanDetailService.selectHtPlanPageCount(pageVO);
//        result.setList(list);
//        result.setTotal((long) count);
//        return success(result);
//    }

    @GetMapping("/export-excel")
    @ApiOperation("导出隐患排查计划详情 Excel")
//    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detail:export')")
    @OperateLog(type = EXPORT)
    public void exportHtPlanDetailExcel(@Valid HtPlanDetailExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<HtPlanDetailDO> list = htPlanDetailService.getHtPlanDetailList(exportReqVO);
        // 导出 Excel
        List<HtPlanDetailExcelVO> datas = HtPlanDetailConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "隐患排查计划详情.xls", "数据", HtPlanDetailExcelVO.class, datas);
    }

}
